#ifndef     __CODEC_H
#define     __CODEC_H

#include <stdint.h>

namespace utils {

inline void encode_uint8(uint8_t *buf, uint8_t val) {
    buf[0] = val;
}

inline void encode_uint16(uint8_t *buf, uint16_t val) {
    buf[0] = val >> 8;
    buf[1] = val;
}

inline void encode_uint32(uint8_t *buf, uint32_t val) {
    buf[0] = val >> 24;
    buf[1] = val >> 16;
    buf[2] = val >> 8;
    buf[3] = val;
}

inline uint8_t decode_uint8(const uint8_t *buf) {
    return buf[0];
}

inline uint16_t decode_uint16(const uint8_t *buf) {
    return (buf[0] << 8) + buf[1];
}

inline uint32_t decode_uint32(const uint8_t *buf) {
    return (buf[0] << 24) +
        (buf[1] << 16) +
        (buf[2] << 8) +
        (buf[3]);
}

}

#endif
